package com.qqgame.hlddz;

import android.app.ActivityOptions;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.qqgame.hlddz.databinding.ActivityMainBinding;


public class MiddleBaiduActivity extends AppCompatActivity {

    public static int display = 0;

//    public static String baiduPackageName = "com.baidu.naviauto.baidu";
    public static String baiduPackageName = "com.ss.android.ugc.aweme";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        ActivityMainBinding binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        openBaidu();

        finish();

    }

    private void openBaidu() {
        try {
            ActivityOptions options = ActivityOptions.makeBasic();
            options.setLaunchDisplayId(display);
            Intent secondIntent = new Intent();
            ComponentName cn = new ComponentName(baiduPackageName, "com.baidu.baidumaps.MapsActivity");
            secondIntent.setComponent(cn);
            //该句很重要，不添加则无法推送到副屏
            secondIntent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(secondIntent, options.toBundle());
        } catch (Exception e) {
            Toast.makeText(this, "e：" + e.getMessage(), Toast.LENGTH_LONG).show();
            e.printStackTrace();
        }
    }


}